package com.hao.statussheet.utils;

import com.hao.statussheet.bean.MusicBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hao on 16/12/4.
 */
public class PalyListUtils {


    // TODO: 16/12/4  牵扯到的同步问题 ,暂时不做处理

    private static List<MusicBean> musicBeanList;


    /**
     * 获取播放集合
     *
     * @return
     */
    public static List<MusicBean> getMusicBeanList() {
        return musicBeanList;
    }

    /**
     * 设置播放集合
     *
     * @param musicBeanList
     */
    public static void addMusicBeanList(List<MusicBean> musicBeanList) {
        if (PalyListUtils.musicBeanList == null) {
            PalyListUtils.musicBeanList = musicBeanList;
        } else {
            PalyListUtils.musicBeanList.addAll(musicBeanList);
        }
    }

    /**
     * 获取播放集合的长度
     *
     * @return
     */
    public static int getSize() {
        return musicBeanList == null ? 0 : musicBeanList.size();
    }


    /**
     * 添加对应的单个数据
     *
     * @param musicBean
     */
    public static void addMusicItem(MusicBean musicBean) {
        if (musicBeanList == null)
            musicBeanList = new ArrayList<>();
        if (!musicBeanList.contains(musicBean))
            musicBeanList.add(musicBean);
    }

    /**
     * 移除对应的数据
     *
     * @param musicBean
     * @return
     */
    public static int removeMusicItem(MusicBean musicBean) {
        if (musicBeanList == null)
            musicBeanList = new ArrayList<>();
        int position = -1;
        if (musicBeanList.contains(musicBean)) {
            position = musicBeanList.indexOf(musicBean);
            musicBeanList.remove(musicBean);
        }
        return position;
    }

    /**
     * 清空数据
     */
    public static void clear() {
        if (PalyListUtils.musicBeanList == null)
            return;
        PalyListUtils.musicBeanList.clear();
        PalyListUtils.musicBeanList = null;
    }
}
